package logic

import (
	"context"
	"stores/mysql"

	"stores/storesrpc/internal/svc"
	"stores/storesrpc/storesrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoreListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreListLogic {
	return &StoreListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StoreListLogic) StoreList(in *storesrpc.StoreListRequest) (*storesrpc.StoreListResponse, error) {
	// todo: add your logic here and delete this line

	var store []mysql.Store
	mysql.DB.Debug().Find(&store)
	var storeList []*storesrpc.StoreList
	for _, m := range store {
		list := storesrpc.StoreList{
			Id:      int64(m.ID),
			Name:    m.Name,
			Address: m.Address,
			Num:     m.Num,
		}
		storeList = append(storeList, &list)
	}
	return &storesrpc.StoreListResponse{
		List: storeList,
	}, nil
}
